const path = require('path');
const webpack = require('webpack');
const htmlWebpackPlugin = require('html-webpack-plugin');
const VueLoaderPlugin = require('vue-loader/lib/plugin');

//webpack 基于node,所以可以使用node语法
module.exports = {
  entry: './src/main.js',
  output: {
    filename: 'bundle.js',
    path: path.resolve(__dirname, 'dist')
  },
  devServer: {
  	open: true,
  	port: 3001,
  	hot: true
  },
  plugins: [
  	new webpack.HotModuleReplacementPlugin(),
  	new htmlWebpackPlugin({
  		template: path.join(__dirname, './src/index.html'),
  		filename: 'index.html'
  	}),
    new VueLoaderPlugin()
  ],
  module: {
    rules: [
      {
        test: /\.css$/,
        use: [ 'style-loader', 'css-loader' ] //从左到右加载
      },
      {
        test: /\.less$/,
        use: [ 'style-loader', 'css-loader' ,'less-loader' ]
      },
      {
        test: /\.scss$/,
        use: [ 'style-loader', 'css-loader' , 'sass-loader' ]
      },
      {
        test: /\.(jpg|jpeg|bmp|gif|png)$/,
        use: 'url-loader?limit=7630&name=[hash:8]-[name].[ext]'
      },
      {
        test: /\.(|eot|svg|ttf|woff|woff2)$/,
        use: 'url-loader'
      },
      {
        test: /\.js$/,
        exclude: /(node_modules|bower_components)/,
        use: {
          loader: 'babel-loader',
          options: {
             presets: ['@babel/preset-env'],
             plugins: [require('@babel/plugin-proposal-class-properties')]
          }
        }
      },
      {
        test: /\.vue$/,
        use: 'vue-loader'
      }
    ]
  },
  resolve: {
    alias: {
      "vue$": "vue/dist/vue.js"
    }
  }
};